package org.qpcr.community.project.model.entity;

import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import org.qpcr.community.project.enums.FileType;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;


@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ExportAmplificationParam extends ExperimentalRecordsInstanceEntity {
    @JsonProperty("MeteringSaveData")
    private JSONArray MeteringSaveData;

    @JsonProperty("MeteringSaveDataAxis")
    private JSONArray MeteringSaveDataAxis;

    @JsonProperty("AmplificationData")
    private JSONArray AmplificationData;

    @JsonProperty("AmplificationDataAxis")
    private JSONArray AmplificationDataAxis;

    @JsonProperty("MeltCurveData")
    private JSONArray MeltCurveData;

    @JsonProperty("MeltCurveDataAxis")
    private JSONArray MeltCurveDataAxis;

    @JsonProperty("MeltCurveCalcData")
    private JSONArray MeltCurveCalcData;

    @JsonProperty("MeltCurveCalcDataAxis")
    private JSONArray MeltCurveCalcDataAxis;

    private String charts;
    private String chatTypeName;

    private String chartImageName;

    private List<MeltParam> meltParams;

    private List<AmplificationParam> amplificationParams;


    public Boolean hasAmplificationData() {
        return null != MeteringSaveData && MeteringSaveData.size() > 0 && null != MeteringSaveDataAxis && MeteringSaveDataAxis.size() > 0;
    }

    public Boolean hasMeltCurveData() {
        return null != MeltCurveData && MeltCurveData.size() > 0 && null != MeltCurveDataAxis && MeltCurveDataAxis.size() > 0;
    }

    public String generateFileName() {
        return String.format("%s-%s-%s-%s", StringUtils.isNotBlank(getChartImageName()) ? getChartImageName() : "", StringUtils.isNotBlank(getItem()) ? getItem() : "", StringUtils.isNotBlank(getName()) ? getName() : "", getCurrentTime());
    }
    public String generateFileName(FileType  fileType) {
        return String.format("%s.%s", this.generateFileName(), fileType.getSuffix());
    }


    public String generateZipFileName() {
        return String.format("%s.%s",LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时mm分ss秒")),FileType.ZIP.getSuffix());
    }
    /**
     * 读取当前系统时间格式yyyy-MM-dd HH:mm:ss
     */
    public String getCurrentTime() {
        // 获取当前日期时间
        LocalDateTime now = LocalDateTime.now();
        // 定义格式器
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 格式化时间
        return now.format(formatter);
    }

    @Data
    public static  class MeltParam {
        private String name;
        private String threshold;
        private String thresholdType;
    }

    @Data
    public static class   AmplificationParam {
        private String name;
        private String threshold;
        private String ct;
        private String start;
        private String end;
    }
}
